<template>
  <div class="avr-block-page">
    <!-- 页面头部 -->
    <div class="page-header">
      <el-page-header @back="goBack" content="AVR闭环系统原理框图">
        <template #title>
          <span class="header-title">整流发电机虚拟训练软件</span>
        </template>
        <template #extra>
          <div class="header-actions">
            <el-button type="primary" :icon="Printer" @click="handlePrint">打印</el-button>
            <el-button :icon="Download" @click="handleDownload">下载PDF</el-button>
          </div>
        </template>
      </el-page-header>
    </div>

    <!-- 内容区域 -->
    <div class="content-wrapper">
      <!-- 标题区域 -->
      <h1 class="content-title">AVR闭环系统原理框图</h1>

      <!-- 原理说明 -->
      <section class="content-section">
        <h2>AVR闭环控制系统概述</h2>
        <p>自动电压调节器(AVR)是发电机组的核心控制设备，通过闭环控制系统实现对发电机输出电压的精确调节。AVR系统基于负反馈原理，实时监测发电机输出电压，并与设定值进行比较，根据偏差大小自动调节励磁电流，从而维持发电机输出电压的稳定。</p>
        
        <p>AVR闭环控制系统具有以下特点：</p>
        <ul>
          <li>响应速度快：能够在几十毫秒内完成电压调节</li>
          <li>调节精度高：电压稳定精度可达±1%</li>
          <li>稳定性好：采用PID控制算法确保系统稳定运行</li>
          <li>保护功能完善：具备多种保护机制确保系统安全</li>
        </ul>
      </section>

      <!-- 原理框图展示 -->
      <section class="content-section">
        <h2>AVR闭环系统原理框图</h2>
        <div class="block-diagram-container">
          <div class="image-container">
            <img src="@/assets/AVR.png" alt="AVR闭环系统原理框图" class="block-image">
            <p class="image-caption">图6-7 AVR闭环系统原理框图</p>
          </div>
          <p class="image-description">该原理框图展示了AVR闭环控制系统的完整结构，包括电压检测、比较器、PID控制器、功率放大器、励磁机、发电机和反馈回路等组成部分。</p>
        </div>
      </section>

      <!-- 系统组成 -->
      <section class="content-section">
        <h2>系统组成及功能</h2>
        <el-tabs type="border-card">
          <el-tab-pane label="电压检测">
            <h3>电压检测模块</h3>
            <p>通过电压互感器(PT)实时检测发电机输出电压，并将检测信号送入比较器与设定值进行比较。</p>
            <ul>
              <li>电压互感器：将高电压信号转换为低电压信号</li>
              <li>信号调理电路：对检测信号进行滤波和放大</li>
              <li>AD转换器：将模拟信号转换为数字信号供控制器处理</li>
            </ul>
          </el-tab-pane>
          
          <el-tab-pane label="比较器">
            <h3>比较器模块</h3>
            <p>将检测到的电压信号与设定值进行比较，计算出电压偏差值，并将偏差信号送入PID控制器。</p>
            <ul>
              <li>偏差计算：实时计算电压偏差</li>
              <li>信号处理：对偏差信号进行预处理</li>
              <li>数据传输：将处理后的信号传输给控制器</li>
            </ul>
          </el-tab-pane>
          
          <el-tab-pane label="PID控制器">
            <h3>PID控制器</h3>
            <p>根据电压偏差信号，采用PID控制算法计算出励磁电流调节量。</p>
            <ul>
              <li>比例调节(P)：快速响应电压变化</li>
              <li>积分调节(I)：消除静态误差</li>
              <li>微分调节(D)：提高系统稳定性</li>
            </ul>
          </el-tab-pane>
          
          <el-tab-pane label="功率放大">
            <h3>功率放大模块</h3>
            <p>将PID控制器输出的控制信号进行功率放大，驱动励磁机励磁绕组。</p>
            <ul>
              <li>功率放大器：放大控制信号</li>
              <li>晶闸管整流电路：控制励磁电流大小</li>
              <li>保护电路：防止过流、过压等异常情况</li>
            </ul>
          </el-tab-pane>
          
          <el-tab-pane label="反馈回路">
            <h3>反馈回路</h3>
            <p>发电机输出电压通过励磁机和旋转整流器作用于发电机转子，形成闭环反馈回路。</p>
            <ul>
              <li>励磁机：产生励磁电流</li>
              <li>旋转整流器：将交流电转换为直流电供给转子</li>
              <li>发电机转子：建立磁场实现发电功能</li>
            </ul>
          </el-tab-pane>
        </el-tabs>
      </section>

      <!-- 控制算法 -->
      <section class="content-section">
        <h2>PID控制算法</h2>
        <p>AVR系统采用经典的PID控制算法，通过比例、积分、微分三种调节作用的组合，实现对发电机输出电压的精确控制。</p>
        
        <el-row :gutter="20">
          <el-col :span="8">
            <el-card class="algorithm-card">
              <template #header>
                <div class="card-header">
                  <el-icon><DataAnalysis /></el-icon>
                  <span>比例调节(P)</span>
                </div>
              </template>
              <div class="card-content">
                <p>输出与偏差成正比，响应速度快，但存在静态误差。</p>
              </div>
            </el-card>
          </el-col>
          
          <el-col :span="8">
            <el-card class="algorithm-card">
              <template #header>
                <div class="card-header">
                  <el-icon><TrendCharts /></el-icon>
                  <span>积分调节(I)</span>
                </div>
              </template>
              <div class="card-content">
                <p>消除静态误差，提高控制精度，但可能影响系统稳定性。</p>
              </div>
            </el-card>
          </el-col>
          
          <el-col :span="8">
            <el-card class="algorithm-card">
              <template #header>
                <div class="card-header">
                  <el-icon><Setting /></el-icon>
                  <span>微分调节(D)</span>
                </div>
              </template>
              <div class="card-content">
                <p>预测偏差变化趋势，提高系统稳定性，减少超调。</p>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </section>


      <!-- 相关知识链接 -->
      <section class="content-section">
        <h2>相关知识链接</h2>
        <div class="knowledge-links">
          <el-card
              v-for="link in relatedLinks"
              :key="link.title"
              class="link-card"
              @click="navigateTo(link.path)"
          >
            <template #header>
              <div class="card-header">
                <el-icon><Connection /></el-icon>
                <span>{{ link.title }}</span>
              </div>
            </template>
            <div class="card-content">
              <p>{{ link.description }}</p>
              <div class="card-actions">
                <el-tag :type="link.type" size="small">{{ link.category }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </section>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { Printer, Download, Connection, DataAnalysis, TrendCharts, Setting } from '@element-plus/icons-vue';

const router = useRouter();

// 技术参数数据

// 相关知识链接
const relatedLinks = ref([
  {
    title: '自动电压调节器(AVR)',
    description: '了解AVR的结构组成和工作原理',
    path: '/principle/avr',
    category: '控制系统',
    type: 'primary'
  },
  {
    title: '励磁机原理',
    description: '了解AVR如何控制励磁机工作',
    path: '/principle/exciter',
    category: '励磁系统',
    type: 'success'
  },
  {
    title: '副励磁机原理',
    description: '了解副励磁机为AVR提供电源的原理',
    path: '/principle/pilot-exciter',
    category: '电源系统',
    type: 'warning'
  },
  {
    title: '发电机组控制',
    description: '掌握完整的发电机组控制系统',
    path: '/principle/control-panel',
    category: '控制系统',
    type: 'danger'
  }
]);

const goBack = () => {
  router.back();
};

const handlePrint = () => {
  window.print();
};

const handleDownload = () => {
  console.log('下载AVR闭环系统原理框图PDF');
};

const navigateTo = (path) => {
  router.push(path);
};
</script>

<style scoped>
.avr-block-page {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
  background-color: #fff;
  padding: 16px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.header-title {
  font-size: 18px;
  font-weight: bold;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.content-wrapper {
  background-color: #fff;
  padding: 24px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.content-title {
  font-size: 28px;
  color: #303133;
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 2px solid #409eff;
}

.content-section {
  margin-bottom: 40px;
}

.content-section h2 {
  font-size: 22px;
  color: #303133;
  margin-bottom: 16px;
  padding-left: 8px;
  border-left: 4px solid #409eff;
}

.content-section h3 {
  font-size: 18px;
  color: #606266;
  margin: 16px 0 12px 0;
}

.content-section p {
  line-height: 1.6;
  color: #606266;
  margin-bottom: 16px;
}

.content-section ul {
  padding-left: 24px;
  margin-bottom: 16px;
}

.content-section li {
  line-height: 1.6;
  color: #606266;
  margin-bottom: 8px;
}

.block-diagram-container {
  text-align: center;
}

.image-container {
  margin-bottom: 20px;
  text-align: center;
}

.block-image {
  max-width: 100%;
  height: auto;
  border: 1px solid #e4e7ed;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.image-caption {
  font-style: italic;
  color: #909399;
  margin-top: 8px;
}

.image-description {
  color: #606266;
}

.algorithm-card {
  height: 100%;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
}

.card-content {
  min-height: 60px;
}

.knowledge-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.link-card {
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
  height: 100%;
}

.link-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
}

.card-content {
  min-height: 80px;
}

.card-actions {
  margin-top: 12px;
}

@media (max-width: 768px) {
  .avr-block-page {
    padding: 12px;
  }

  .content-wrapper {
    padding: 16px;
  }

  .content-title {
    font-size: 24px;
  }

  .content-section h2 {
    font-size: 20px;
  }

  .knowledge-links {
    grid-template-columns: 1fr;
  }

  .header-actions {
    flex-direction: column;
    gap: 8px;
  }
}

@media print {
  .page-header, .header-actions {
    display: none;
  }

  .avr-block-page {
    padding: 0;
    background-color: #fff;
  }

  .content-wrapper {
    padding: 0;
    box-shadow: none;
  }
}
</style>